package com.chenyue.cm.moudules.system.controller;

import com.chenyue.cm.base.bean.PageVo;
import com.chenyue.cm.base.bean.Pageable;
import com.chenyue.cm.base.controller.BaseController;
import com.chenyue.cm.bean.Success;
import com.chenyue.cm.common.constant.C;
import com.chenyue.cm.common.utils.RequestUtil;
import com.chenyue.cm.common.utils.StringUtils;
import com.chenyue.cm.moudules.system.service.SysLogService;
import com.chenyue.cm.system.domain.SysLog;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 【系统模块】====>【日志管理】
 *
 * @author chenyue
 * @Description: TODO
 * @file:
 * @throws @date
 * 2018/11/20 17:31
 */
@Controller
@RequestMapping("/master/log")
@Api(value = "系统管理-日志", tags = "系统管理-日志")
@ApiSort(7)
public class SysLogController extends BaseController {

    @Autowired
    private SysLogService sysLogService;

    /**
     * 【页面跳转】====>【系统模块】====>【日志模块】===>日志管理列表页
     *
     * @return
     */
    @RequestMapping()
    public String syslog(HttpServletRequest request, HttpServletResponse response, Model model) {
        return C.THEME_Prefix + "system/syslog/sysLogList";
    }

    /**
     * 【API】====>【系统模块】====>【日志模块】===>获取日志数据
     *
     * @param request
     * @param sysLog
     * @return
     */
    @ResponseBody
    @PostMapping(value = "/querySyslog")
    @ApiOperation(value = "【S7001】获取操作日志列表（分页）", notes = "获取操作日志列表（分页）")
    @ApiOperationSupport(order = 1)
    public Success querySysLog(HttpServletRequest request, SysLog sysLog) {
        Pageable pageInfo = RequestUtil.getPageable(request);
        pageInfo.getPageOrderParam().put("c_time", false);
        PageVo<SysLog> result = sysLogService.getPageBean(pageInfo, SysLog.class);
        return Success.success(result);
    }

    /**
     * 【API】====>【系统模块】====>【日志模块】===>删除日志数据
     *
     * @param id
     * @return
     */
    @PostMapping("/remove/{id}")
    @ResponseBody
    @ApiOperation(value = "【S7002】删除操作日志", notes = "删除操作日志")
    @ApiOperationSupport(order = 2)
    public Success remove(@PathVariable("id") String id) {
        if (StringUtils.isEmpty(id)) {
            return Success.error("错误的参数类型");
        }
        this.sysLogService.deleteByPrimaryKey(id);
        return Success.success();
    }

}
